package com.itboye.textileexpres.util;

import java.util.Timer;
import java.util.TimerTask;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.itboye.textileexpres.R;
import com.itboye.textileexpres.base.MainApplication;

public class MyToast {
	static Toast toast;

	// public void showMyToast(final Toast toast, final int cnt) {
	// final Timer timer = new Timer();
	// timer.schedule(new TimerTask() {
	// @Override
	// public void run() {
	// toast.show();
	// }
	// }, 0, 3000);
	// new Timer().schedule(new TimerTask() {
	// @Override
	// public void run() {
	// toast.cancel();
	// timer.cancel();
	// }
	// }, cnt);
	// }

	public static void toast(String text) {
		LayoutInflater inflater = LayoutInflater.from(MainApplication
				.getContext());
		View view = inflater.inflate(R.layout.toast, null);
		TextView textView = (TextView) view.findViewById(R.id.toast_tv);
		if ("缺少uid参数".equals(text)) {
			textView.setText("还未登录，快登录吧");
		}
		textView.setText(text);
		toast = new Toast(MainApplication.getContext());
		toast.setDuration(Toast.LENGTH_LONG);
		toast.setView(view);
		final Timer timer = new Timer();
		timer.schedule(new TimerTask() {
			@Override
			public void run() {
				toast.show();
			}
		}, 0, 3000);
		new Timer().schedule(new TimerTask() {
			@Override
			public void run() {
				toast.cancel();
				timer.cancel();
			}
		}, 1000);
	}
}
